package com.example.administrator.pandanotes;

/**
 * Created by Administrator on 2018-06-12.
 */
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;

public class BookAdapter extends ArrayAdapter {
    private int resourceId;
    public BookAdapter(Context context, int resource, List BookList) {
        super(context, resource,BookList);
        resourceId = resource;
}
    @Override
    public View getView(int position,View convertView, ViewGroup parent)
    {
        Books books = (Books) getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId,null);//实例化一个View对象
        ImageView imageView = (ImageView) view.findViewById(R.id.fruit_image);//获取该布局内的图片视图
        TextView textView = (TextView)view.findViewById(R.id.fruit_name);//获取该布局内的文本视图
        imageView.setImageResource(books.getBook_imageId());              //为图片视图设置图片资源
        textView.setText(books.getBook_name());                          //为文本视图设置文本资源
        return view;
    }
}
